#include <iostream>
#include <unistd.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
  pid_t id = fork();
  if(id == 0)
  {
    sleep(2);
    execl("/bin/ls", "ls", "-a", "-l", nullptr);
    exit(2);//如果代码执行到这里，表示子进程程序替换错误，返回退出码为2
  }
  else 
  {
      pid_t rid = waitpid(id, nullptr, 0);
      if(rid > 0)
      {
        std::cout << "进程等待成功！" << std::endl;
      }
  }
  return 0;
}
